 import { createRouter , createWebHistory } from "vue-router";
 import { useUserStore } from "@/stores/modules/user"
import { compose } from "element-plus/es/components/table/src/util";

 const router = createRouter({
    history:createWebHistory(),
    routes:[
        {
            path:'/login',
            component: ()=>import('@/views/Login.vue')
         },
        {
            path:"/",
            component: ()=>import('@/views/Layout.vue'),
            children:[
                {
                    path:'/welcome',
                    component:()=>import('@/views/Welcome.vue')
                }, 
                {
                    path:'/user',
                    component:()=>import('@/views/UserManager.vue')
                },
                {
                    path:'dept',
                    component:()=>import('@/views/DeptManager.vue')
                },
            ]
         }
    
    ]
 })
 router.beforeEach((to,from)=>{
   const userStore = useUserStore()
   if(to.path!='/login' && !userStore.token){
       return '/login'
   }
   return true
})

 export default router;